<?

/********************************************
* gallery.php
*
* This page displays photos of robots in The Blue Alliance system. 
* It won't scale well.
*
********************************************/

//include files
include "config.php";
include "db.php";
include "tbatv_lib.php";

//get passed arguments
$year = $_GET['year'];
$year = stripslashes($year);

//get Directory from year.
switch ($year) {
    case 2009:
        $dir = "pictures/2009";
        break;
	case 2008:
		$dir = "pictures/2008";
		break;
	case 2007:
		$dir = "pictures/2007";
		break;
	case 2006:
		$dir = "pictures/2006";
		break;
	default:
		$year = 2009;
		$dir = "pictures/2009";
		break;
}

$title = " - Robot Gallery " . $year;

include "header.php";

?>
<h1>Robot Photos from <? echo $year ?></h1>
<table class="table_alt">
<?

if (is_dir($dir)) {
   if ($dh = opendir($dir)) {
		while (false!== ($file = readdir($dh))) { 
			if ($file != "." && $file != ".." && !is_dir($file)) { 
				$namearr = split('\.',$file); 
				$the_array[] = $file; //builds jpgs into an array.
			} 
		}
		
		sort($the_array);
		
		$col = 1; //preinitialize table maker
		$row = 0;
		
        foreach ($the_array as $file) {
			$findme  = '.jpg';
			$pos = strpos($file, $findme);
		    
			$teamnumber = substr($file,0,-4);
			$fullsize = "pictures/".$year."/".$teamnumber.".jpg";
			
			if (file_exists($dir . "/thumbs/" . $file)) {
				$file = $dir . "/thumbs/" . $file;
			} else {
				$file = "/images/144square.jpg";
			}
			
			if ($pos === false) {
			} else {
				if ($col == "1") {
				   echo "<tr class=\"table_row$row\">";
				}
				echo "<td align=\"center\">";
				echo "<a href=\"http://www.thebluealliance.net/tbatv/team.php?team=" . $teamnumber . "\" title=\"$file\"><strong style=\"font-size: 18px; color: black; \">" . $teamnumber . "</strong></a><br /><br />";
				echo "<a href=\"$fullsize\" rel=\"lightbox\"><img src=\"$file\" style=\"border: 1px solid white;\" /></a>";
				echo "</td>";
				
				if ($col == "3") {
					echo "</tr>";
					$col = 0;
					if ($row == 0) {
						$row = 1;
					} else {
						$row = 0;
					}
				}
				$col++;
			}
       } //end foreach
       closedir($dh);
   }
}

?>
</table>
<?

include "footer.php";

?>